package com.tg.data.http.entity;

import android.os.Parcel;
import android.os.Parcelable;

import com.tange.base.toolkit.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class NotifyDataBean implements Parcelable {
    private final int is_push;

    protected NotifyDataBean(Parcel in) {
        is_push = in.readInt();
        item = in.createTypedArrayList(NotifyItemBean.CREATOR);
        undisturbed = in.readParcelable(UndisturbedBean.class.getClassLoader());
        interval = in.readInt();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(is_push);
        dest.writeTypedList(item);
        dest.writeParcelable(undisturbed, flags);
        dest.writeInt(interval);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<NotifyDataBean> CREATOR = new Creator<NotifyDataBean>() {
        @Override
        public NotifyDataBean createFromParcel(Parcel in) {
            return new NotifyDataBean(in);
        }

        @Override
        public NotifyDataBean[] newArray(int size) {
            return new NotifyDataBean[size];
        }
    };

    public List<NotifyItemBean> getItem() {
        return item;
    }

    private final List<NotifyItemBean> item;

    public UndisturbedBean getUndisturbed() {
        return undisturbed;
    }

    public void setUndisturbed(UndisturbedBean undisturbed) {
        this.undisturbed = undisturbed;
    }

    private UndisturbedBean undisturbed;
    private int interval;

    public void setInterval(int interval) {
        this.interval = interval;
    }


    public List<String> getPush_params() {
        List<String> list = new ArrayList<>();
        for (NotifyItemBean notifyItemBean : item){
            list.add(notifyItemBean.getTag());
        }
        return list;
    }

    public List<String> getEnabledPush_params() {
        final List<String> list = new ArrayList<>();
        if (item == null) return list;
        for (NotifyItemBean notifyItemBean : item){
            if (notifyItemBean.isStatus()) {
                list.add(notifyItemBean.getTag());
            }
        }
        return list;
    }

    private boolean isExist(String str){
        for (NotifyItemBean notifyItemBean : item){
            if (StringUtils.equalsIgnoreCase(str, notifyItemBean.getTag())){
                return true;
            }
        }
        return false;
    }

    public void setPush_params(List<String> list){
        for (String str : list){
            if (!isExist(str)){
                NotifyItemBean notifyItemBean = new NotifyItemBean();
                notifyItemBean.setTag(str);
                item.add(notifyItemBean);
            }
        }
    }

    public int getInterval(){
        return interval;
    }

}
